<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
	</style>
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">
		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item" style="margin-bottom: 5px;">
					<div class="layui-inline">
						<div class="layui-input-inline">
							<input type="text" name="item"  autocomplete="off" placeholder="请输入项目名称" class="layui-input">
						</div>
						
					</div>
					<div class="layui-inline">
						<button type="button" class="layui-btn layui-btn-primary"  onclick="get_seek()"><i class="layui-icon"></i> 搜 索</button>
					</div>
				</div>
			</form>
		</fieldset>
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-success layui-btn-sm data-add-btn" lay-event="items">添加项目</button>
				<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="jindu">账户进度</button>
			</div>
		</script>
		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
		<script type="text/html" id="currentTableBar">
			<!--<a style="{{d.is_deliver==1?'display:none;':''}}" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>-->
		</script>
		<script type="text/html" id="statusTpl">
  			<!-- 这里的 checked 的状态只是演示 -->
  			<input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="statusDemo" {{ d.status == 1 ? 'checked' : '' }}>
		</script>
	</div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
//添加项目
function add_items(){
	layer.open({
        type: 2,
        title:'添加项目',
        area: ['60%', '70%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('items_add')}"
    });
    //layer.full(index);
}
//账户进度
function get_acc(){
	layer.open({
        type: 2,
        title:'账户进度',
        area: ['60%', '70%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('account_jindu')}"
    });
    //layer.full(index);
}
	var $,form,table,laydate
	layui.use(['form', 'table', 'tableSelect', 'laydate'], function () {
		$ = layui.jquery , form = layui.form , table = layui.table , laydate = layui.laydate;
		var index1 = parent.layer.getFrameIndex(window.name);
		console.log($(window).height());
		table.render({
			elem: '#currentTableId',
			id:'items_list',
			url: '{:url("index")}?t=json',
			height: $(window).height() - 150,//640,
			method : 'post',
			toolbar: '#toolbarDemo',
			cols: [[
				{ field: 'channel_name', title: '端口',width:"120"},
				{ field: 'name_id', title: '账户(ID:)',width:"220"},
				{ field: 'name', title: '项目名称' ,width:"220", templet: function (d) {
					var s = d.is_deliver ==1?"已投递":"未投递" 
                    return d.name + '(' +s+ ')'
                }},
                { field: 'customer_name', title: '客户',width:"120"},
                { field: 'industry_name', title: '行业',width:"120"},
				{ field: 'media_name', title: '媒介',width:"180"},
				{ field: 'rebates', title: '返点(客户/服务费/渠道%)',width:200 , templet: function (d) {
						var s = d.is_deliver ==1?"已投递":"未投递" 
	                    return d.rebates + ' / '+d.service+' / '+d.channel_rebate
	            }},
				{ field: 'status', title: '项目状态',toolbar: '#statusTpl',width:"120"},
				{ field: 'type', title: '项目类型',width:"120",templet: function(d){
			          return d.type==1?'跑消耗':'跑表单'
			    }},
				{ field: 'yesterday_currency', title: '昨日消耗',width:120,templet: function(d){
			          return d.yesterday_currency?d.yesterday_currency:'0.00'
			    }},
			    { field: 'total_money', title: '总消耗',width:120},
			    { field: 'note', title: '备注',width:"200"},
			    { field: 'create_time', title: '开启时间',width:"180"},
			    { title: '操作', minWidth: 150, fixed: 'right', toolbar: '#currentTableBar',align:'center'}
			]],
			limit: 30,
			page: true,
			skin: 'line'
		});
		 //监听状态操作
        form.on('switch(statusDemo)', function (obj) {
            //layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
           
            var x = obj.elem.checked;
            var id = this.value;
            layer.confirm('您确认要修改项目状态吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
            	get_save_item_status(obj, id, x)
            });
            obj.elem.checked = !x;
            form.render();
        });
		 
      	//修改项目状态
        function get_save_item_status(obj, id, status) {
            sta = status ? '1' : "0";
            layer.load(1, {shade: [0.5, '#676a6c']});
            $.post("{:url('get_save_item_status')}?t=json", {id: id, status: sta}, function (data) {
                layer.closeAll();
                if (data.code == 1) {
                    layer.msg(data['msg'], {icon: 6});
                    obj.elem.checked = status;
                    form.render();
                } else {
                    layer.msg(data['msg'], {icon: 5});
                }

            });
        }
		/**
		 * toolbar监听事件
		 */
		table.on('toolbar(currentTableFilter)', function (obj) {
			switch (obj.event) {
				case 'items':
					add_items();
				break;
				case 'jindu':
					get_acc();
				break;
			}
			
		});
		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'delete':
					layer.confirm('您确认要删除项目吗？', {
		                btn: ['确认', '取消'] //按钮
		            }, function () {
		            	layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
						$.post("{:url('item_del')}?t=json",{id:data.id},function(da){
							layer.closeAll();
							if(da['code'] == 1){
								obj.del(); 
								layer.msg(da['msg'], {icon: 6});
							}else{
							 layer.msg(da['msg'], { icon : 5 });
							}
						});
		            });
					
					
				break;
			}
			//提交审核
			function get_audit(id){
				layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
				$.post("{:url('audit_pass')}?t=json",{id:id},function(da){
					layer.closeAll();
					if(da['code'] == 1){
					 //重载数据表格
					 get_apply(da['msg']);
					}else{
					 layer.msg(da['msg'], { icon : 5 });
					}
				});
			}
			
		});
		//监听行单击事件
		table.on('row(currentTableFilter)', function(obj){
			  layer.photos({
				  photos: obj.tr
				  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
				});
			});

	});
	function get_load(msg){
		table.reload('items_list', {
			  url: '{:url("index")}?t=json',
			});
		layer.msg(msg, {icon: 6});
	}
	function get_seek(){
		var name = $("input[name=item]").val();
		table.reload('items_list', {
			  url: '{:url("index")}?t=json',
			  where:{name:name}
			});
	}
	
</script>

</body>
</html>